/**
 * 获取当前视角
 */
function getCamera() {
    const heading = Cesium.Math.toDegrees(viewer.camera.heading);
    const pitch = Cesium.Math.toDegrees(viewer.camera.pitch);
    const roll = Cesium.Math.toDegrees(viewer.camera.roll);
    const cartographic = viewer.camera.positionCartographic;
    const { height, longitude, latitude } = cartographic;

    let info = {
        lng: Cesium.Math.toDegrees(longitude),
        lat: Cesium.Math.toDegrees(latitude),
        height: height,
        heading: heading,
        pitch: pitch,
        roll: roll,
    }

    console.log('当前视角', info)
    return info;
}

/**
 * 正北
 */
function toNorth() {
    let pick = new Cesium.Cartesian2($(window).width() / 2, $(window).height() / 2);
    let cartesian = viewer.scene.globe.pick(viewer.camera.getPickRay(pick), viewer.scene);
    let cartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian);
    let longitude = Cesium.Math.toDegrees(cartographic.longitude);
    let latitude = Cesium.Math.toDegrees(cartographic.latitude);
    let height = viewer.camera.positionCartographic.height;
    let ratio = 1 / Math.abs(Math.sin(viewer.camera.pitch));

    viewer.camera.setView({
        destination: Cesium.Cartesian3.fromDegrees(longitude, latitude, height * ratio),
        orientation: {
            heading: Cesium.Math.toRadians(0.0),  // east, default value is 0.0 (north)
            pitch: Cesium.Math.toRadians(-90),    // default value (looking down)
            roll: 0.0                             // default value
        }
    });
}
